<?php

#### General PHP Configuration
ini_set('error_reporting', E_ALL & ~E_NOTICE);
setlocale(LC_CTYPE, 'de_DE.utf-8');
ini_set('log_errors', true);
ini_set('error_log', realpath(dirname(__FILE__).'/../logs/error.log'));
ini_set('display_errors', true);
ini_set('magic_quotes_gpc', false);
ini_set('include_path', '.'.PATH_SEPARATOR.realpath(dirname(__FILE__).'/../library/'));

require_once '../library/Zend/Loader.php';

/**
 * Add autoload support for Zend Framework compatible classes
 */
function __autoload($class)
{
    if ('Zend' == substr($class, 0, 4) || 
        'CWAC' == substr($class, 0, 4) ||
        'Indexer' == substr($class, 0, 7)) {
        Zend_Loader::loadClass($class);
    }
}

Indexer_Service::$logTarget = realpath('../logs/error.log');
// Set up a logging filter
Indexer_Service::getLog()->addFilter(new Zend_Log_Filter_Priority(Zend_Log::INFO));

// Do some common configuration tasks
if (file_exists('../application/config.php')) {
    require '../application/config.php';
}

// set it in a controller
$ctrl = Zend_Controller_Front::getInstance();
$ctrl->setParam('noViewRenderer', true);
$r = $ctrl->getRouter();
/*
$restAction = array("controller" => "rest", "action" => "service");
$r->addRoute('restService', new Zend_Controller_Router_Route('rest/:method/*', $restAction));
$r->addRoute('restSearch',  new Zend_Controller_Router_Route('rest/search/:phrase', $restAction));
*/

// set controller directory and dispatch
$ctrl->setControllerDirectory(realpath('../application/controllers'));
$ctrl->returnResponse(true);
$response = $ctrl->dispatch();

/*********** SET TO FALSE ON PRODUCTION WEBSITES !!!!!!! ***********/
$response->renderExceptions(true);
/*******************************************************************/

echo $response;
